﻿// Copyright © Microsoft Corporation.  All Rights Reserved.
// This code released under the terms of the 
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

using System;
using System.Windows;
using System.Windows.Data;
using Microsoft.Windows.Design.PropertyEditing;

namespace Microsoft.Expression.Prototyping.Mockups.Design.PropertyEditors
{
	#region PropertyValueEditors

	public class IconImageInlineEditor : PropertyValueEditor
	{
		public IconImageInlineEditor()
		{
			this.InlineEditorTemplate = IconPickerDictionary.IconPickerLineTemplate;
		}
	}

	public class CursorImageInlineEditor : PropertyValueEditor
	{
		public CursorImageInlineEditor()
		{
			this.InlineEditorTemplate = IconPickerDictionary.CursorPickerLineTemplate;
		}
	}

	public class OverlayImageInlineEditor : PropertyValueEditor
	{
		public OverlayImageInlineEditor()
		{
			this.InlineEditorTemplate = IconPickerDictionary.OverlayImagePickerLineTemplate;
		}
	}
	#endregion

	#region IconPickerDictionary

	public static class IconPickerDictionary
	{
		private static ResourceDictionary dictionary = (ResourceDictionary)Application.LoadComponent(new Uri("/Microsoft.Expression.Prototyping.Mockups.Design.PropertyEditors;component/IconChooserDictionary.xaml", UriKind.Relative));

		public static DataTemplate IconPickerLineTemplate
		{
			get
			{
				return dictionary["IconPickerLineTemplate"] as DataTemplate;
			}
		}

		public static DataTemplate CursorPickerLineTemplate
		{
			get
			{
				return dictionary["CursorPickerLineTemplate"] as DataTemplate;
			}
		}

		public static DataTemplate OverlayImagePickerLineTemplate
		{
			get
			{
				return dictionary["OverlayImagePickerLineTemplate"] as DataTemplate;
			}
		}
	}
	#endregion
	
	#region Converters

	[ValueConversion(typeof(string), typeof(IconImage))]
	public class StringToIconImageConverter : IValueConverter
	{
		public object Convert(object value, Type targetType,
			object parameter, System.Globalization.CultureInfo culture)
		{
			return (IconImage)Enum.Parse(typeof(IconImage), (string)value);
		}

		public object ConvertBack(object value, Type targetType,
			object parameter, System.Globalization.CultureInfo culture)
		{
			return ((IconImage)value).ToString();
		}
	}

	[ValueConversion(typeof(string), typeof(CursorImage))]
	public class StringToCursorImageConverter : IValueConverter
	{
		public object Convert(object value, Type targetType,
			object parameter, System.Globalization.CultureInfo culture)
		{
			return (CursorImage)Enum.Parse(typeof(CursorImage), (string)value);
		}

		public object ConvertBack(object value, Type targetType,
			object parameter, System.Globalization.CultureInfo culture)
		{
			return ((CursorImage)value).ToString();
		}
	}

	[ValueConversion(typeof(CursorImage), typeof(IconImage))]
	public class CursorToIconImageConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			return (IconImage)Enum.Parse(typeof(IconImage), ((CursorImage)value).ToString(), true);
		}

		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			throw new NotImplementedException();
		}
	}

	[ValueConversion(typeof(string), typeof(CursorOverlay))]
	public class StringToOverlayImageConverter : IValueConverter
	{
		public object Convert(object value, Type targetType,
			object parameter, System.Globalization.CultureInfo culture)
		{
			return (CursorOverlay)Enum.Parse(typeof(CursorOverlay), (string)value);
		}

		public object ConvertBack(object value, Type targetType,
			object parameter, System.Globalization.CultureInfo culture)
		{
			return ((CursorOverlay)value).ToString();
		}
	}

	[ValueConversion(typeof(CursorOverlay), typeof(IconImage))]
	public class OverlayImageToIconImageConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			return (IconImage)Enum.Parse(typeof(IconImage), ((CursorOverlay)value).ToString(), true);
		}

		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			throw new NotImplementedException();
		}
	}
	#endregion
}
